import { tableServiceInterface } from "@/common/interface/table.interface";
import { $systemMenuAdd, $systemMenuDelete, $systemMenuList, $systemMenuUpdate, $systemMenuDetail } from "@/apis/system/menu/menu";
import { systemMenuListInterface, systemMenuUpdateInterface, systemMenuAddInterface } from "@/apis/system/menu/menu.interface";
import handleTree from "@/common/utils/handleTree";
import to from "await-to-js";
export default class MenuService implements tableServiceInterface {
  async getTable(e: systemMenuListInterface): Promise<any> {
    const [err, res]: any = await to($systemMenuList(e));
    if (!err) {
      res.data.data = handleTree(res.data.data, "menuId");
      return Promise.resolve(res);
    } else {
      return Promise.reject(err);
    }
  }
  delete(e: string): Promise<any> {
    return $systemMenuDelete(e);
  }
  edit(e: systemMenuUpdateInterface): Promise<any> {
    return $systemMenuUpdate(e);
  }
  add(e: systemMenuAddInterface): Promise<any> {
    return $systemMenuAdd(e);
  }
  detail(e: string): Promise<any> {
    return $systemMenuDetail(e);
  }
}